/**
 * @file qq_cnf_msg_handle.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_QQ != 0
/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static void watch_qq_free_msg(void * msg);
static void watch_qq_free_get_qr_cnf_msg(mmi_msg_qq_get_qr_cnf_t * msg);
static void watch_qq_free_query_qr_cnf_msg(mmi_msg_qq_query_qr_cnf_t * msg);
static void watch_qq_free_get_msg_cnf_msg(mmi_msg_qq_get_msg_cnf_t * msg);
static void watch_qq_free_get_friend_list_cnf_msg(mmi_msg_qq_get_friend_list_cnf_t * msg);
static void watch_qq_free_get_friend_msg_cnf_msg(mmi_msg_qq_get_friend_msg_cnf_t * msg);
static void watch_qq_free_get_recent_contact_cnf_msg(mmi_msg_qq_get_recent_contact_cnf_t * msg);
static void watch_qq_free_get_friend_info_cnf_msg(mmi_msg_qq_get_friend_info_cnf_t * msg);
static void watch_qq_free_undecided_cnf_msg(mmi_msg_qq_get_undecided_cnf_t * msg);
static void watch_qq_free_data_cnf_msg(mmi_msg_qq_get_data_cnf_t * msg);
/**********************
 *  STATIC VARIABLES
 **********************/
static bool qq_getting_msg_flag = false;
static bool qq_new_msg_pushed = false;
/**********************
 *      MACROS
 **********************/
#define CNT_MSG_HANDLE_TIME  1000
/**********************
 *   GLOBAL FUNCTIONS
***********************/

void watch_qq_register_with_openid_cnf(watch_qq_register_with_openid_cnf_t * watch_registercnf)
{
    mmi_msg_qq_cnf_t * msg = (mmi_msg_qq_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_cnf_t));
    msg->header.MsgId = MMI_QQ_REGISTER_CNF;
    msg->result = watch_registercnf->result;
    lv_mem_free(watch_registercnf);
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_register_with_openid_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_qr_cnf(watch_qq_get_qr_cnf_t * get_qrcnf)
{
    printf("%s\n", __FUNCTION__);
    mmi_msg_qq_get_qr_cnf_t * msg = (mmi_msg_qq_get_qr_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_qr_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_get_qr_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_QR_CNF;
    msg->get_qrcnf = get_qrcnf;
#if BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_qr_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_query_qr_cnf(watch_qq_query_qr_cnf_t * query_qrcnf)
{
    mmi_msg_qq_query_qr_cnf_t * msg = (mmi_msg_qq_query_qr_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_query_qr_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_query_qr_cnf_t));
    msg->header.MsgId = MMI_QQ_QUERY_QR_CNF;
    msg->query_qrcnf = query_qrcnf;
#if BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_query_qr_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_msg_cnf(watch_qq_get_msg_cnf_t * get_msgcnf)
{
    mmi_msg_qq_get_msg_cnf_t * msg = (mmi_msg_qq_get_msg_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_msg_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_get_msg_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_MSG_CNF;
    msg->get_msgcnf = get_msgcnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_msg_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_send_msg_cnf(watch_qq_send_msg_cnf_t * send_msgcnf)
{
    mmi_msg_qq_seng_msg_cnf_t * msg = (mmi_msg_qq_seng_msg_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_seng_msg_cnf_t));
    msg->header.MsgId = MMI_QQ_SEND_MSG_CNF;
    msg->result = send_msgcnf->result;
    msg->time = send_msgcnf->server_time;
    msg->msg_seqid = (uint16_t)send_msgcnf->msg_seqid;
    lv_mem_free(send_msgcnf);
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_send_msg_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_friend_msg_cnf(watch_qq_get_friend_msg_cnf_t * get_friend_msgcnf)
{
    mmi_msg_qq_get_friend_msg_cnf_t * msg = (mmi_msg_qq_get_friend_msg_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_friend_msg_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_FRIEND_MSG_CNF;
    msg->get_friend_msgcnf = get_friend_msgcnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_friend_msg_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_friend_list_cnf(watch_qq_get_friend_list_cnf_t * get_friend_listcnf)
{
    mmi_msg_qq_get_friend_list_cnf_t * msg = (mmi_msg_qq_get_friend_list_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_friend_list_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_FRIEND_LIST_CNF;
    msg->friend = get_friend_listcnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_friend_list_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_recent_contact_cnf(watch_qq_get_recent_contact_cnf_t * get_recent_contactcnf)
{
    mmi_msg_qq_get_recent_contact_cnf_t * msg = (mmi_msg_qq_get_recent_contact_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_recent_contact_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_RECENT_CONTACT_CNF;
    msg->get_recent_contactcnf = get_recent_contactcnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_recent_contact_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_find_friend_cnf(watch_qq_find_friend_cnf_t * find_friendcnf)
{
    mmi_msg_qq_find_friend_cnf_t * msg = (mmi_msg_qq_find_friend_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_find_friend_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_find_friend_cnf_t));
    msg->header.MsgId = MMI_QQ_FIND_FRIEND_CNF;
    msg->result = find_friendcnf->result;
    memcpy(msg->openid, find_friendcnf->openid, 64);
    lv_mem_free(find_friendcnf);
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_find_friend_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_friend_info_cnf(watch_qq_get_friend_info_cnf_t * get_friendcnf)
{
    mmi_msg_qq_get_friend_info_cnf_t * msg = (mmi_msg_qq_get_friend_info_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_friend_info_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_get_friend_info_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_FRIEND_INFO_CNF;
    msg->get_friendcnf = get_friendcnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_friend_info_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_ack_add_friend_cnf(watch_qq_ack_add_friend_cnf_t * ack_add_friendcnf)
{
    mmi_msg_qq_cnf_t * msg = (mmi_msg_qq_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_cnf_t));
    msg->header.MsgId = MMI_QQ_ACK_ADD_FRIEND_CNF;
    msg->result = ack_add_friendcnf->result;
    lv_mem_free(ack_add_friendcnf);
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_ack_add_friend_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_add_friend_cnf(watch_qq_add_friend_cnf_t * add_friendcnf)
{
    mmi_msg_qq_cnf_t * msg = (mmi_msg_qq_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_cnf_t));
    msg->header.MsgId = MMI_QQ_ADD_FRIEND_CNF;
    msg->result = add_friendcnf->result;
    lv_mem_free(add_friendcnf);
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_add_friend_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_delete_friend_cnf(watch_qq_delete_friend_cnf_t * delete_friendcnf)
{
    mmi_msg_qq_cnf_t * msg = (mmi_msg_qq_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_cnf_t));
    msg->header.MsgId = MMI_QQ_DELETE_FRIEND_CNF;
    msg->result = delete_friendcnf->result;
    lv_mem_free(delete_friendcnf);
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_delete_friend_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_undecided_cnf(watch_qq_get_undecided_cnf_t * get_undecidedcnf)
{
    mmi_msg_qq_get_undecided_cnf_t * msg = (mmi_msg_qq_get_undecided_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_undecided_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_get_undecided_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_UNDECIDED_CNF;
    msg->get_undecidedcnf = get_undecidedcnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_undecided_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void watch_qq_get_data_cnf(watch_qq_get_data_cnf_t * get_datacnf)
{
    printf("%s\n", __FUNCTION__);
    mmi_msg_qq_get_data_cnf_t * msg = (mmi_msg_qq_get_data_cnf_t *)lv_mem_alloc(sizeof(mmi_msg_qq_get_data_cnf_t));
    memset(msg, 0, sizeof(mmi_msg_qq_get_data_cnf_t));
    msg->header.MsgId = MMI_QQ_GET_DATA_CNF;
    msg->get_datacnf = get_datacnf;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_get_data_cnf_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

void app_adaptor_qq_new_message_ind(uint8_t msg_type)
{
    printf("%s: msg_type = %d\n", __FUNCTION__, msg_type);
    Hal_Pm_WakeUp();
    mmi_msg_qq_new_msg_notify_t * msg = (mmi_msg_qq_new_msg_notify_t *)lv_mem_alloc(sizeof(mmi_msg_qq_new_msg_notify_t));
    memset(msg, 0, sizeof(mmi_msg_qq_new_msg_notify_t));
    msg->header.MsgId = MMI_QQ_NEW_MSG_NOTIFY;
    msg->msg_type = msg_type;
#ifdef BUILD_IN_PC_SIMULATOR
    Hal_Timer_Start(CNT_MSG_HANDLE_TIME, watch_qq_new_message_notify_handle, (void *)msg, false);
#else
    Hal_Send_Message((TASK_ID)gui_task_id, (void *)msg);
#endif
}

//MMI handle cnf msg
void watch_qq_reset_get_msg_flag(void)
{
    qq_getting_msg_flag = false;
    qq_new_msg_pushed = false;
}

void watch_qq_new_message_notify_handle(void * msg)
{
    if(!watch_get_lcd_status()) watch_set_lcd_status(true);
    mmi_msg_qq_new_msg_notify_t * new_msg = (mmi_msg_qq_new_msg_notify_t *)msg;
    printf("%s: qq_getting_msg_flag = %d, qq_new_msg_pushed = %d\n", __FUNCTION__, qq_getting_msg_flag, qq_new_msg_pushed);
    if(new_msg->msg_type == QQ_NEW_FRIEND) {
         qq_create_new_message(NULL, new_msg->msg_type);
    } else {
        if(!watch_is_qq_activity()) {
            qq_create_new_message(NULL, new_msg->msg_type);
        } else {
            if(qq_getting_msg_flag) {
                if(!qq_new_msg_pushed)
                    qq_new_msg_pushed = true;
            } else {
                qq_getting_msg_flag = true;
                qq_get_msg();
            }
        }
    }
    watch_qq_free_msg(msg);
}

void watch_qq_register_with_openid_cnf_handle(void * msg)
{
    if(!watch_is_qq_activity()) {
        watch_qq_free_msg(msg);
        return;
    }
    mmi_msg_qq_cnf_t * reg_msg = (mmi_msg_qq_cnf_t *)msg;
    printf("%s:result = %d\n", __FUNCTION__, reg_msg->result);
    if(reg_msg->result == WATCH_QQ_OK) {
        lv_qq_obj_ext_t * ext = qq_get_ext();
        if(ext->login_state == 0 && ext->login != NULL) {
            qq_destroy_login();
            qq_create_main();
        } else {
            qq_clear_contact_list();
            qq_free_my_cookie();
            qq_create_switch_account();
        }
    } else {
        qq_show_login_failed();
    }
    watch_qq_free_msg(msg);
}

void watch_qq_get_qr_cnf_handle(void * msg)
{
    mmi_msg_qq_get_qr_cnf_t * get_msg = (mmi_msg_qq_get_qr_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_get_qr_cnf_msg(get_msg);
        return;
    }
    printf("%s:result = %d\n", __FUNCTION__, get_msg->get_qrcnf->result);
    if(get_msg->get_qrcnf->result == WATCH_QQ_OK) {
        watch_qq_get_data_req_t * get_data_req = lv_mem_alloc(sizeof(watch_qq_get_data_req));
        get_data_req->url = lv_strdup(get_msg->get_qrcnf->string);
        qq_add_get_data_info(QQ_DATA_QR, 0, get_data_req->url);
        watch_qq_get_data_req(get_data_req);
    } else {
        qq_create_get_qr_failed();
    }
    watch_qq_free_get_qr_cnf_msg(get_msg);
}

void watch_qq_query_qr_cnf_handle(void * msg)
{
    mmi_msg_qq_query_qr_cnf_t * query_msg = (mmi_msg_qq_query_qr_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_query_qr_cnf_msg(msg);
        return;
    }
    qq_update_qrcode(query_msg->query_qrcnf->result, query_msg->query_qrcnf->openid, query_msg->query_qrcnf->access_token);
    watch_qq_free_query_qr_cnf_msg(msg);
}

void watch_qq_get_msg_cnf_handle(void * msg)
{
    mmi_msg_qq_get_msg_cnf_t * msg_info = (mmi_msg_qq_get_msg_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_get_msg_cnf_msg(msg_info);
        return;
    }
    qq_show_chat_new_message(msg_info->get_msgcnf);
    watch_qq_free_get_msg_cnf_msg(msg_info);

    qq_getting_msg_flag = false;
    if(qq_new_msg_pushed) {
        qq_new_msg_pushed = false;
        qq_get_msg();
    }
}

void watch_qq_send_msg_cnf_handle(void * msg)
{
    if(!watch_is_qq_activity()) {
        watch_qq_free_msg(msg);
        return;
    }
    mmi_msg_qq_seng_msg_cnf_t * send_msg = (mmi_msg_qq_seng_msg_cnf_t *)msg;
    qq_send_msg_result(send_msg->result, send_msg->time, send_msg->msg_seqid);
    watch_qq_free_msg(msg);
}

void watch_qq_get_friend_msg_cnf_handle(void * msg)
{
    mmi_msg_qq_get_friend_msg_cnf_t * friend_msg = (mmi_msg_qq_get_friend_msg_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_get_friend_msg_cnf_msg(friend_msg);
        return;
    }
    qq_get_msg_over(friend_msg->get_friend_msgcnf->lastmsg_time, friend_msg->get_friend_msgcnf->random);
    if(friend_msg->get_friend_msgcnf->msg_infocnt > 0) {
        qq_add_msg_into_list(&friend_msg->get_friend_msgcnf->msg_infos_ll);
    }
    watch_qq_free_get_friend_msg_cnf_msg(friend_msg);
}

void watch_qq_get_friend_list_cnf_handle(void * msg)
{
    mmi_msg_qq_get_friend_list_cnf_t * friend_list  = (mmi_msg_qq_get_friend_list_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_get_friend_list_cnf_msg(friend_list);
        return;
    }
    if(friend_list->friend->user_infocnt > 0) {
        qq_create_friends_list(friend_list->friend);
    }
    watch_qq_free_get_friend_list_cnf_msg(friend_list);
}

void watch_qq_get_recent_contact_cnf_handle(void * msg)
{
    mmi_msg_qq_get_recent_contact_cnf_t * recent = (mmi_msg_qq_get_recent_contact_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_get_recent_contact_cnf_msg(recent);
        return;
    }
    printf("%s: recent user cnt = %d\n", __FUNCTION__, recent->get_recent_contactcnf->user_infocnt);
    if(recent->get_recent_contactcnf->result == WATCH_QQ_OK && recent->get_recent_contactcnf->user_infocnt > 0) {
        qq_create_recent_contacts_list(&recent->get_recent_contactcnf->user_infos_ll);
    } else {
        qq_no_msg_recently();
    }
    watch_qq_free_get_recent_contact_cnf_msg(recent);
}

void watch_qq_find_friend_cnf_handle(void * msg)
{
    if(!watch_is_qq_activity()) {
        watch_qq_free_msg(msg);
        return;
    }
    mmi_msg_qq_find_friend_cnf_t * find_msg = (mmi_msg_qq_find_friend_cnf_t *)msg;
    if(find_msg->result == WATCH_QQ_OK)
        qq_get_friend_info(find_msg->openid);
    else
        qq_show_find_friend_failed();
    watch_qq_free_msg(msg);
}

void watch_qq_get_friend_info_cnf_handle(void * msg)
{
    mmi_msg_qq_get_friend_info_cnf_t * get_msg = (mmi_msg_qq_get_friend_info_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_get_friend_info_cnf_msg(get_msg);
        return;
    }
    if(get_msg->get_friendcnf->result == WATCH_QQ_OK) {
        qq_update_friend_info(&get_msg->get_friendcnf->user_info);
    }
    watch_qq_free_get_friend_info_cnf_msg(get_msg);
}

void watch_qq_ack_add_friend_cnf_handle(void * msg)
{
    if(!watch_is_qq_activity()) {
        watch_qq_free_msg(msg);
        return;
    }
    mmi_msg_qq_cnf_t * ack_msg = (mmi_msg_qq_cnf_t *)msg;
    if(ack_msg->result == WATCH_QQ_OK) {
        watch_qq_get_undecided_req_t * undecided_req = lv_mem_alloc(sizeof(watch_qq_get_undecided_req_t));
        undecided_req->validation_seq = 0;
        undecided_req->query_type = WATCH_QQ_QUERY_TYPE_ALL;
        undecided_req->start_index = 0;
        undecided_req->reqnum = MMI_QQ_GET_VALID_MSG_CNT;
        watch_qq_login_info_t * info = watch_qq_get_last_login_info();
        memcpy(undecided_req->from_openid, info->openid, 64);
        watch_qq_get_undecided_req(undecided_req);
        lv_mem_free(info);
    }
    watch_qq_free_msg(msg);
}

void watch_qq_add_friend_cnf_handle(void * msg)
{
    if(!watch_is_qq_activity()) {
        watch_qq_free_msg(msg);
        return;
    }
    mmi_msg_qq_cnf_t * add_msg = (mmi_msg_qq_cnf_t *)msg;
    qq_add_friend_req_result(add_msg->result);
    watch_qq_free_msg(msg);
}

void watch_qq_delete_friend_cnf_handle(void * msg)
{
    mmi_msg_qq_cnf_t * delete = (mmi_msg_qq_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_msg(msg);
        return;
    }
    qq_del_friend_result(delete->result);
    watch_qq_free_msg(msg);
}

void watch_qq_get_undecided_cnf_handle(void * msg)
{
    mmi_msg_qq_get_undecided_cnf_t * undecided = (mmi_msg_qq_get_undecided_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_undecided_cnf_msg(undecided);
        return;
    }
    if(undecided->get_undecidedcnf->result == WATCH_QQ_OK && undecided->get_undecidedcnf->get_result == WATCH_QQ_GET_TYPE_SUCCESS) {
        if(undecided->get_undecidedcnf->msg_successreaded.totle > 0) {
            qq_create_validation_msg_list(&undecided->get_undecidedcnf->msg_successreaded);
        }
    }
    watch_qq_free_undecided_cnf_msg(undecided);
}

void watch_qq_get_data_cnf_handle(void * msg)
{
    printf("%s\n", __FUNCTION__);
    mmi_msg_qq_get_data_cnf_t * data_msg = (mmi_msg_qq_get_data_cnf_t *)msg;
    if(!watch_is_qq_activity()) {
        watch_qq_free_data_cnf_msg(data_msg);
        return;
    }
    qq_show_data(data_msg->get_datacnf);
    watch_qq_free_data_cnf_msg(data_msg);
}

/**********************
 *   STATIC FUNCTIONS
***********************/
static void watch_qq_free_msg(void * msg)
{
#ifdef BUILD_IN_PC_SIMULATOR
    lv_mem_free(msg);
#endif
}

static void watch_qq_free_get_qr_cnf_msg(mmi_msg_qq_get_qr_cnf_t * msg)
{
    if(msg->get_qrcnf->string)
        lv_mem_free(msg->get_qrcnf->string);
    lv_mem_free(msg->get_qrcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_query_qr_cnf_msg(mmi_msg_qq_query_qr_cnf_t * msg)
{
    lv_mem_free(msg->query_qrcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_get_msg_cnf_msg(mmi_msg_qq_get_msg_cnf_t * msg)
{
    if(msg->get_msgcnf->cookie)
        lv_mem_free(msg->get_msgcnf->cookie);
    if(msg->get_msgcnf->msg_infocnt > 0) {
        watch_qq_msg_info_t * node = _lv_ll_get_head(&msg->get_msgcnf->msg_infos_ll);
        while(node) {
            if(node->msg_elementcnt > 0) {
                watch_qq_msg_element_t * el_node = _lv_ll_get_head(&node->msg_elements_ll);
                while(el_node) {
                    if(el_node->msg_content) lv_mem_free(el_node->msg_content);
                    el_node = _lv_ll_get_next(&node->msg_elements_ll, el_node);
                }
                _lv_ll_clear(&node->msg_elements_ll);
            }
            node = _lv_ll_get_next(&msg->get_msgcnf->msg_infos_ll, node);
        }
        _lv_ll_clear(&msg->get_msgcnf->msg_infos_ll);
    }
    if(msg->get_msgcnf->user_infocnt > 0) {
        watch_qq_user_info_t * node = _lv_ll_get_head(&msg->get_msgcnf->user_infos_ll);
        while(node) {
            if(node->headurl) lv_mem_free(node->headurl);
            if(node->remark) lv_mem_free(node->remark);
            if(node->nickname) lv_mem_free(node->nickname);
            node = _lv_ll_get_next(&msg->get_msgcnf->user_infos_ll, node);
        }
        _lv_ll_clear(&msg->get_msgcnf->user_infos_ll);
    }
    lv_mem_free(msg->get_msgcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_get_friend_msg_cnf_msg(mmi_msg_qq_get_friend_msg_cnf_t * msg)
{
    if(msg->get_friend_msgcnf->msg_infocnt > 0) {
        watch_qq_msg_info_t * node = _lv_ll_get_head(&msg->get_friend_msgcnf->msg_infos_ll);
        while(node) {
            if(node->msg_elementcnt > 0) {
                watch_qq_msg_element_t * el_node = _lv_ll_get_head(&node->msg_elements_ll);
                while(el_node) {
                    if(el_node->msg_content)
                        lv_mem_free(el_node->msg_content);
                    el_node = _lv_ll_get_next(&node->msg_elements_ll, el_node);
                }
                _lv_ll_clear(&node->msg_elements_ll);
            }
            node = _lv_ll_get_next(&msg->get_friend_msgcnf->msg_infos_ll, node);
        }
        _lv_ll_clear(&msg->get_friend_msgcnf->msg_infos_ll);
    }
    if(msg->get_friend_msgcnf->user_infocnt > 0) {
        watch_qq_user_info_t * node = _lv_ll_get_head(&msg->get_friend_msgcnf->user_infos_ll);
        while(node) {
            if(node->headurl) lv_mem_free(node->headurl);
            if(node->remark) lv_mem_free(node->remark);
            if(node->nickname) lv_mem_free(node->nickname);
            node = _lv_ll_get_next(&msg->get_friend_msgcnf->user_infos_ll, node);
        }
        _lv_ll_clear(&msg->get_friend_msgcnf->user_infos_ll);
    }

    lv_mem_free(msg->get_friend_msgcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_get_friend_list_cnf_msg(mmi_msg_qq_get_friend_list_cnf_t * msg)
{
    if(msg->friend->user_infocnt > 0) {
        watch_qq_user_info_t * node = _lv_ll_get_head(&msg->friend->user_infos_ll);
        while(node) {
            if(node->headurl) lv_mem_free(node->headurl);
            if(node->remark) lv_mem_free(node->remark);
            if(node->nickname) lv_mem_free(node->nickname);
            node = _lv_ll_get_next(&msg->friend->user_infos_ll, node);
        }
        _lv_ll_clear(&msg->friend->user_infos_ll);
    }
    lv_mem_free(msg->friend);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_get_recent_contact_cnf_msg(mmi_msg_qq_get_recent_contact_cnf_t * msg)
{
    if(msg->get_recent_contactcnf->user_infocnt > 0) {
        watch_qq_user_info_t * node = _lv_ll_get_head(&msg->get_recent_contactcnf->user_infos_ll);
        while(node) {
            if(node->headurl) lv_mem_free(node->headurl);
            if(node->remark) lv_mem_free(node->remark);
            if(node->nickname) lv_mem_free(node->nickname);
            node = _lv_ll_get_next(&msg->get_recent_contactcnf->user_infos_ll, node);
        }
        _lv_ll_clear(&msg->get_recent_contactcnf->user_infos_ll);
    }
    lv_mem_free(msg->get_recent_contactcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_get_friend_info_cnf_msg(mmi_msg_qq_get_friend_info_cnf_t * msg)
{
    if(msg->get_friendcnf->user_info.headurl)
        lv_mem_free(msg->get_friendcnf->user_info.headurl);

    if(msg->get_friendcnf->user_info.nickname)
        lv_mem_free(msg->get_friendcnf->user_info.nickname);

    if(msg->get_friendcnf->user_info.remark)
        lv_mem_free(msg->get_friendcnf->user_info.remark);
    lv_mem_free(msg->get_friendcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_undecided_cnf_msg(mmi_msg_qq_get_undecided_cnf_t * msg)
{
    if(msg->get_undecidedcnf->msg_successreaded.totle > 0) {
        watch_qq_validation_msg_t * node = (watch_qq_validation_msg_t *)_lv_ll_get_head(&msg->get_undecidedcnf->msg_successreaded.validation_msgs_ll);
        while(node) {
            if(node->validation_msg)
                lv_mem_free(node->validation_msg);
            node = _lv_ll_get_next(&msg->get_undecidedcnf->msg_successreaded.validation_msgs_ll, node);
        }
        _lv_ll_clear(&msg->get_undecidedcnf->msg_successreaded.validation_msgs_ll);
    }
    lv_mem_free(msg->get_undecidedcnf);
    watch_qq_free_msg(msg);
}

static void watch_qq_free_data_cnf_msg(mmi_msg_qq_get_data_cnf_t * msg)
{
    if(msg->get_datacnf->url) {
        lv_mem_free(msg->get_datacnf->url);
    }
    if(msg->get_datacnf->data) {
        lv_mem_free(msg->get_datacnf->data);
    }
    lv_mem_free(msg->get_datacnf);
    watch_qq_free_msg(msg);
}

#endif /*USE_LV_WATCH_QQ*/
